package com.xunwulian.cmeb.command;

import com.xunwulian.base.constant.ConstantBean;
import com.xunwulian.base.exception.ErrorCodeException;
import org.json.JSONArray;

/**
 * 用户当月GPRS查询
 */
public class GprsUsedCommand extends Command {

    private String msisdn;

    public GprsUsedCommand(Receiver receiver, String msisdn) {
        super(APICode.GPRSUSEDCURRENTMONTH, receiver);
        this.msisdn = msisdn;
    }

    @Override
    public String getParam() {
        return "msisdn=" + msisdn;
    }

    @Override
    public Long execute() throws ErrorCodeException {
        JSONArray result = receiver.actionPost(api, getParam());

        long gprs = ConstantBean.FAIL_VALUE_LONG;
        if (null != result && result.length() != 0) {
            gprs = result.getJSONObject(0).getLong("total_gprs");
        }

        return gprs;
    }
}
